package com.jiangyg.mall.authz.support.authentication;

import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.core.utils.Logger;
import com.jiangyg.mall.core.utils.WebUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述：没有访问权限的异常处理
 *
 * @author jiangyg
 * @version 4.0
 * @date 2021-10-11
 */
@Slf4j
public class AccessDeniedExceptionHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException ex) {
        Logger.info(log, () -> String.format("请求[%s]没有访问权限异常：", WebUtils.getRequestPath(request)), ex);
        WebUtils.out(response, Result.instance("423"));
    }

}
